package com.xiaoran.RMQ_1.test2;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.xiaoran.RMQ_1.utlis.RabbitMqUtils;

import java.util.Queue;

public class Work_Consumer {
    public static final  String QUEUE_NAME="hello";
    public static void main(String args[]) throws Exception{
        System.out.println("C2准备接受消息。。。。。。。。。。。。。");
     //创建信道
        Channel channel=RabbitMqUtils.getChannel();
    //接收消息消费的回调
        DeliverCallback deliverCallback=(consumerTag,message)->{
          System.out.println("接收到的消息："+new String(message.getBody()));
        };
        //消息失败的回调
        CancelCallback cancelCallback=consumerTag->{
          System.out.println(consumerTag+" 消息消费失败");
        };
    //接收消息
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);

}
}
